package com.example.cunion.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.cunion.entity.PostActClass;
import com.example.cunion.exception.CunionException;
import com.example.cunion.service.PostActClassService;
import com.example.cunion.mapper.PostActClassMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* @author Aero
* @description 针对表【post_act_class(帖子活动分类表)】的数据库操作Service实现
* @createDate 2023-09-29 22:10:20
*/
@Service
public class PostActClassServiceImpl extends ServiceImpl<PostActClassMapper, PostActClass>
    implements PostActClassService{

    @Resource
    private PostActClassMapper postActClassMapper;

   @Override
    public ArrayList<HashMap> searchAllPostClass() {
        //调用postActClassMapper的searchAllPostClass方法，获取所有帖子分类信息
        ArrayList<HashMap> list = postActClassMapper.searchAllPostClass();
        return list;
    }

    @Override
    public Integer addPostActClassByMp(PostActClass postActClass) {
        int insert = postActClassMapper.insert(postActClass);
        if (insert != 1){
            throw new CunionException("添加失败");
        }
        return insert;
    }

    @Override
    public Integer deletedPostActClassByMp(String postActClassId) {
        int result = postActClassMapper.deleteById(postActClassId);
        if (result != 1){
            throw new CunionException("删除失败！");
        }
        return result;
    }

    @Override
    public Integer updatePostActClassByMp(PostActClass postActClass) {
        int result = postActClassMapper.updateById(postActClass);
        if (result != 1){
            throw new CunionException("修改失败");
        }
        return result;
    }

    @Override
    public List<PostActClass> searchPostActClassByMp(Integer start, Integer length) {
        Page<PostActClass> page = new Page<>(start, length);
        QueryWrapper<PostActClass> QueryWrapper = new QueryWrapper<>();
        Page<PostActClass> selectPage = postActClassMapper.selectPage(page, QueryWrapper);
        List<PostActClass> list = selectPage.getRecords();
        return list;
    }
}




